home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / misc / gnuplot-3.7src.lha / gnuplot-3.7src / gnuplot-3.7.lha / gnuplot-3.7 / term / hp500c.trm < prev    next >
Text File  |  1998-12-14  |  14KB  |  544 lines

  1. /*
  2.  * $Id: hp500c.trm,v 1.17 1998/04/14 00:17:48 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - hp500c.trm */
  7.  
  8. /*[
  9.  * Copyright 1990 - 1993, 1998
  10.  *
  11.  * Permission to use, copy, and distribute this software and its
  12.  * documentation for any purpose with or without fee is hereby granted,
  13.  * provided that the above copyright notice appear in all copies and
  14.  * that both that copyright notice and this permission notice appear
  15.  * in supporting documentation.
  16.  *
  17.  * Permission to modify the software is granted, but not the right to
  18.  * distribute the complete modified source code.  Modifications are to
  19.  * be distributed as patches to the released version.  Permission to
  20.  * distribute binaries produced by compiling modified sources is granted,
  21.  * provided you
  22.  *   1. distribute the corresponding source modifications from the
  23.  *    released version in the form of a patch file along with the binaries,
  24.  *   2. add special version identification to distinguish your version
  25.  *    in addition to the base release version number,
  26.  *   3. provide your name and address as the primary contact for the
  27.  *    support of your modified version, and
  28.  *   4. retain our contact information in regard to use of the base
  29.  *    software.
  30.  * Permission to distribute the released version of the source code along
  31.  * with corresponding source modifications in the form of a patch file is
  32.  * granted with same provisions 2 through 4 for binary distributions.
  33.  *
  34.  * This software is provided "as is" without express or implied warranty
  35.  * to the extent permitted by applicable law.
  36. ]*/
  37.  
  38. /*
  39.  * This file is included by ../term.c.
  40.  *
  41.  * This terminal driver supports:
  42.  *  hpdj 500c
  43.  *
  44.  * AUTHORS
  45.  *  John Engels      -- \
  46.  *  Russell Lang     ----> HPLJII.trm
  47.  *  Maurice Castro   -- /
  48.  *  UdoHessenauer    ----> derived this version from the above one
  49.  *
  50.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  51.  * 
  52.  */
  53.  
  54. /* The following HP Deskjet500c  driver uses generic bit mapped graphics
  55.    routines from bitmap.c to build up a bit map in memory.  The driver
  56.    interchanges colomns and lines in order to access entire lines
  57.    easily and returns the lines to get bits in the right order :
  58.    (x,y) -> (y,XMAX-1-x). */
  59. /* This interchange is done by calling b_makebitmap() with reversed 
  60.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  61.    will then perform the interchange before each pixel is plotted */
  62. /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
  63.    of Jyrki Yli-Nokari */
  64.  
  65. /*
  66.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  67.  */
  68.  
  69. #include "driver.h"
  70.  
  71. #ifdef TERM_REGISTER
  72. register_term(hp500c)
  73. #endif
  74.  
  75. #ifdef TERM_PROTO
  76. TERM_PUBLIC void HP500Coptions __PROTO((void));
  77. TERM_PUBLIC void HP500Cinit __PROTO((void));
  78. TERM_PUBLIC void HP500Creset __PROTO((void));
  79. TERM_PUBLIC void HP500Clinetype __PROTO((int linetype));
  80. TERM_PUBLIC void HP500Cgraphics __PROTO((void));
  81. TERM_PUBLIC void HP500Ctext __PROTO((void));
  82. #define HP500Ctext_angle b_text_angle
  83. #define HP500Cput_text b_put_text
  84. #define HP500Cmove b_move
  85. #define HP500Cvector b_vector
  86. /* default values for term_tbl */
  87. #define HP500C_75PPI_XMAX (1920/4)
  88. #define HP500C_75PPI_YMAX (1920/4)
  89. #define HP500C_75PPI_HCHAR (1920/4/6)
  90. #define HP500C_75PPI_VCHAR (1920/4/10)
  91. #define HP500C_75PPI_VTIC 5
  92. #define HP500C_75PPI_HTIC 5
  93.  
  94. #define GOT_HP500C_PROTO
  95. #endif
  96.  
  97. #ifndef TERM_PROTO_ONLY
  98. #ifdef TERM_BODY
  99.  
  100.  
  101. /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
  102.    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
  103.  
  104. #define HP500C_DPP (hpdj_dpp)    /* dots per pixel */
  105. #define HP500C_PPI (300/HP500C_DPP)    /* pixel per inch */
  106. /* make XMAX and YMAX a multiple of 8 */
  107. #define HP500C_XMAX (8*(unsigned int)(xsize*1920/HP500C_DPP/8.0+0.9))
  108. #define HP500C_YMAX (8*(unsigned int)(ysize*1920/HP500C_DPP/8.0+0.9))
  109.  
  110. /* Courier font with 6 lines per inch */
  111. #define HP500C_VCHAR (HP500C_PPI/6)
  112. /* Courier font with 10 caracters per inch */
  113. #define HP500C_HCHAR (HP500C_PPI/10)
  114.  
  115.  
  116. /* Save current cursor position */
  117. #define HP500C_PUSH_CURSOR fputs("\033&f0S",gpoutfile)
  118. /* Restore cursor position */
  119. #define HP500C_POP_CURSOR fputs("\033&f1S",gpoutfile)
  120.  
  121. /* be sure to use courier font with 6lpi and 10cpi */
  122. #define HP500C_COURIER fputs("\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D",gpoutfile)
  123.  
  124.  
  125. static int HPcompress __PROTO((unsigned char *op, unsigned char *oe,
  126.                    unsigned char *cp));
  127. static unsigned char HPcomplement __PROTO((int c));
  128. static int HPcompress_to_TIFF __PROTO((unsigned char *op, unsigned char *oe,
  129.                        unsigned char *cp));
  130. static int HPnocompress __PROTO((unsigned char *op, unsigned char *oe,
  131.                  unsigned char *cp));
  132.  
  133. static int hpdj_dpp = 4;
  134. static int HP_COMP_MODE = 0;
  135.  
  136. /* bm_pattern not appropriate for 300ppi graphics */
  137. #ifndef GOT_300_PATTERN
  138. #define GOT_300_PATTERN
  139. static unsigned int b_300ppi_pattern[] =
  140. {
  141.     0xffff, 0x1111,
  142.     0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff
  143. };
  144. #endif
  145.  
  146.  
  147. TERM_PUBLIC void HP500Coptions()
  148. {
  149.     char opt[6];
  150.  
  151. #define HPDJCERROR "expecting dots per inch size 75, 100, 150 or 300 and/or compression method"
  152.     while (!END_OF_COMMAND) {
  153.     if (token[c_token].length > 4)
  154.         int_error(HPDJCERROR, c_token);
  155.  
  156.     /* almost_equals() won't accept numbers - use strcmp() instead */
  157.     capture(opt, c_token, c_token, 6);
  158.     if (!strcmp(opt, "75")) {
  159.         hpdj_dpp = 4;
  160.         HP_COMP_MODE = 0;
  161.  
  162.     } else if (!strcmp(opt, "100")) {
  163.         hpdj_dpp = 3;
  164.         HP_COMP_MODE = 0;
  165.     } else if (!strcmp(opt, "150")) {
  166.         hpdj_dpp = 2;
  167.         HP_COMP_MODE = 0;
  168.     } else if (!strcmp(opt, "300")) {
  169.         hpdj_dpp = 1;
  170.         HP_COMP_MODE = 0;
  171.     } else if (!strcmp(opt, "rle")) {
  172.         HP_COMP_MODE = 1;
  173.     } else if (!strcmp(opt, "tiff")) {
  174.         HP_COMP_MODE = 2;
  175.     }
  176.     c_token++;
  177.     }
  178.  
  179.     term->xmax = HP500C_XMAX;
  180.     term->ymax = HP500C_YMAX;
  181.     switch (hpdj_dpp) {
  182.     case 1:
  183.     strcpy(term_options, "300");
  184.     term->v_tic = 15;
  185.     term->h_tic = 15;
  186.     break;
  187.     case 2:
  188.     strcpy(term_options, "150");
  189.     term->v_tic = 8;
  190.     term->h_tic = 8;
  191.     break;
  192.     case 3:
  193.     strcpy(term_options, "100");
  194.     term->v_tic = 6;
  195.     term->h_tic = 6;
  196.     break;
  197.     case 4:
  198.     strcpy(term_options, "75");
  199.     term->v_tic = 5;
  200.     term->h_tic = 5;
  201.     break;
  202.     }
  203.     switch (HP_COMP_MODE) {
  204.     case 0:
  205.     strcat(term_options, " no comp");
  206.     break;
  207.     case 1:
  208.     strcat(term_options, " RLE");
  209.     break;
  210.     case 2:
  211.     strcat(term_options, " TIFF");
  212.     break;
  213.     case 3:            /* not implemented yet */
  214.     strcat(term_options, " Delta Row");
  215.     break;
  216.     }
  217. }
  218.  
  219. TERM_PUBLIC void HP500Cinit()
  220. {
  221.     /* HBB 980226: all changes to term-> fields *must* happen here, not
  222.      * in graphics() !*/
  223.     switch (hpdj_dpp) {
  224.     case 1:
  225.     b_charsize(FNT13X25);
  226.     term->v_char = FNT13X25_VCHAR;
  227.     term->h_char = FNT13X25_HCHAR;
  228.     break;
  229.     case 2:
  230.     b_charsize(FNT13X25);
  231.     term->v_char = FNT13X25_VCHAR;
  232.     term->h_char = FNT13X25_HCHAR;
  233.     break;
  234.     case 3:
  235.     b_charsize(FNT9X17);
  236.     term->v_char = FNT9X17_VCHAR;
  237.     term->h_char = FNT9X17_HCHAR;
  238.     break;
  239.     case 4:
  240.     b_charsize(FNT5X9);
  241.     term->v_char = FNT5X9_VCHAR;
  242.     term->h_char = FNT5X9_HCHAR;
  243.     break;
  244.     }
  245. }
  246.  
  247. TERM_PUBLIC void HP500Creset()
  248. {
  249. #ifdef VMS
  250.     fflush_binary();
  251. #endif
  252. }
  253.  
  254.  
  255.  
  256. /* HP DeskJet 500c routines */
  257.  
  258. TERM_PUBLIC void HP500Clinetype(linetype)
  259. int linetype;
  260. {
  261.     if (linetype < 0)
  262.     linetype = 7;
  263.     else if (linetype >= 8) {
  264.     linetype %= 8;
  265.     }
  266.     switch (linetype) {
  267.     case 0:
  268.     linetype = 6;
  269.     break;
  270.     case 1:
  271.     linetype = 5;
  272.     break;
  273.     case 2:
  274.     linetype = 3;
  275.     break;
  276.     case 3:
  277.     linetype = 2;
  278.     break;
  279.     case 4:
  280.     linetype = 1;
  281.     break;
  282.     case 5:
  283.     linetype = 4;
  284.     break;
  285.     case 6:
  286.     linetype = 7;
  287.     }
  288.     b_setvalue(linetype);
  289.  
  290. }
  291.  
  292. /*
  293. void HP500Cpoint(x,y,value)
  294. int x;
  295. int y;
  296. int value;
  297. {
  298.      HP500Clinetype(value);
  299.      do_point(x,y,value);
  300. }
  301. */
  302.  
  303. TERM_PUBLIC void HP500Cgraphics()
  304. {
  305.     /* HBB 980226: moved block of code from here to init() */
  306.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  307.        setting b_rastermode to TRUE */
  308.     b_makebitmap(HP500C_YMAX, HP500C_XMAX, 3);
  309.     b_rastermode = TRUE;
  310. }
  311.  
  312. /*
  313.  * Run-length encoding for the DeskJet. We have pairs of <count>
  314.  * <what>, where count goes from 0 (meaning one count) to 255
  315.  * this might double the size of the image.
  316.  */
  317.  
  318. static int HPcompress(op, oe, cp)
  319. unsigned char *op, *oe, *cp;
  320. {
  321.     unsigned char *ce = cp;
  322.     while (op < oe) {
  323.     unsigned char prevchar;
  324.     unsigned char count;
  325.  
  326.     prevchar = *op;        /* remember char */
  327.     count = 1;        /* its read the first time */
  328.  
  329.     while (++op < oe && *op == prevchar && count < 255) {
  330.             /* set op to the next char */
  331.         count++;        /* and count it  */
  332.     }
  333.     *ce++ = --count;    /* were ready, so correct the count */
  334.     *ce++ = prevchar;    /* and store <what> */
  335.     }
  336.     *ce = 0;            /* just to be safe   */
  337.     return ce - cp;        /* length of  cbufs */
  338. }
  339.  
  340. static unsigned char HPcomplement(c)
  341. int c;
  342. {
  343.     return (unsigned char) (256 - c);
  344. }
  345.  
  346.  
  347. static int HPcompress_to_TIFF(op, oe, cp)
  348. unsigned char *op;        /* original pointer */
  349. unsigned char *oe;        /* end of orig string */
  350. unsigned char *cp;        /* pointer for compressed data */
  351. {
  352.     unsigned char *countposition;
  353.     unsigned char *ce = cp;
  354.     while (op < oe) {
  355.     unsigned char prevchar;
  356.     unsigned char count;
  357.  
  358.     prevchar = *op;        /* gelesenes Zeichen aufbewaren */
  359.     count = 1;        /* bisher wurde es einmal gelesen */
  360.  
  361.     while (++op < oe && *op == prevchar && count < 128) {
  362.         count++;
  363.     }
  364.     *ce = HPcomplement(count - 1);
  365.         /* remember count for building blocks of literal bytes */
  366.     countposition = ce++;
  367.     *ce++ = prevchar;
  368.  
  369.     if (count < 2) {
  370.         while (op < oe && (prevchar != *op || *op != *(op + 1))) {
  371.                 /* only use rle for at leat 3 equal bytes */
  372.         *ce++ = *op;
  373.         count++;
  374.         prevchar = *op++;
  375.         if (op > oe)
  376.             puts("FATAL op> oe!!\n");
  377.         }
  378.         if (op < oe && prevchar == *op) {
  379.         op--;
  380.         count--;
  381.         ce--;
  382.         }
  383.         *countposition = count - 1;
  384.     }
  385.     }
  386.     return ce - cp;
  387.  
  388. }
  389.  
  390. static int HPnocompress(op, oe, cp)
  391. unsigned char *op;
  392. unsigned char *oe;
  393. unsigned char *cp;
  394. {
  395.     unsigned char *ce = cp;
  396.     while (op < oe)
  397.     *ce++ = *op++;
  398.     return ce - cp;
  399. }
  400.  
  401. /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
  402.    hopefully compatible with other HP Deskjet printers */
  403.  
  404. TERM_PUBLIC void HP500Ctext()
  405. {
  406.     register int x, j, row, count = 0;
  407.     unsigned char *obuf, *oe, *cbuf, *ce;
  408.  
  409.     if ((obuf = (unsigned char *) malloc(100 * b_psize)) == 0)
  410.     puts("FATAL!-- couldn't get enough memory for obuf");
  411.     if ((cbuf = (unsigned char *) malloc(400 * b_psize)) == 0)
  412.     puts("FATAL!-- couldn't get enough memory for cbuf");
  413.  
  414.     oe = obuf;
  415.  
  416.     fprintf(gpoutfile, "\
  417. \033*t%dR\
  418. \033*r1A\
  419. \033*b%1dM\
  420. \033*r%dS\
  421. \033*r-3U",
  422.         HP500C_PPI,
  423.         HP_COMP_MODE,
  424.         b_ysize);
  425.  
  426.     /* dump bitmap in raster mode */
  427.     for (x = b_xsize - 1; x >= 0; x--) {
  428.     row = (b_ysize / 8) - 1;
  429.     for (j = row; j >= 0; j--) {
  430.         *oe++ = (char) (*((*b_p)[j] + x));
  431.     }
  432.     switch (HP_COMP_MODE) {
  433.     case 2:
  434.         count = HPcompress_to_TIFF(obuf, oe, cbuf);
  435.         break;
  436.     case 1:
  437.         count = HPcompress(obuf, oe, cbuf);
  438.         break;
  439.     case 0:
  440.         count = HPnocompress(obuf, oe, cbuf);
  441.         break;
  442.     }
  443.     fprintf(gpoutfile, "\033*b%dV", count);
  444.     ce = cbuf;
  445.     while (count--)
  446.         fputc(*ce++, gpoutfile);
  447.     oe = obuf;
  448.  
  449.     for (j = row; j >= 0; j--) {
  450.         *oe++ = (char) (*((*b_p)[j + b_psize] + x));
  451.     }
  452.     switch (HP_COMP_MODE) {
  453.     case 2:
  454.         count = HPcompress_to_TIFF(obuf, oe, cbuf);
  455.         break;
  456.     case 1:
  457.         count = HPcompress(obuf, oe, cbuf);
  458.         break;
  459.     case 0:
  460.         count = HPnocompress(obuf, oe, cbuf);
  461.         break;
  462.  
  463.     }
  464.  
  465.     fprintf(gpoutfile, "\033*b%dV", count);
  466.     ce = cbuf;
  467.     while (count--)
  468.         fputc(*ce++, gpoutfile);
  469.     oe = obuf;
  470.  
  471.     for (j = row; j >= 0; j--) {
  472.         *oe++ = (char) (*((*b_p)[j + (2 * b_psize)] + x));
  473.     }
  474.     switch (HP_COMP_MODE) {
  475.     case 2:
  476.         count = HPcompress_to_TIFF(obuf, oe, cbuf);
  477.         break;
  478.     case 1:
  479.         count = HPcompress(obuf, oe, cbuf);
  480.         break;
  481.     case 0:
  482.         count = HPnocompress(obuf, oe, cbuf);
  483.         break;
  484.     }
  485.     fprintf(gpoutfile, "\033*b%dW", count);
  486.     ce = cbuf;
  487.     while (count--)
  488.         fputc(*ce++, gpoutfile);
  489.     oe = obuf;
  490.  
  491.     }
  492.     fputs("\033*rbC", gpoutfile);
  493.     free(cbuf);
  494.     free(obuf);
  495.     b_freebitmap();
  496.  
  497. #ifndef VMS
  498.     /* most vms spoolers add a formfeed character */
  499.     putc('\f', gpoutfile);
  500. #endif /* !VMS */
  501. }
  502.  
  503. #endif /* TERM_BODY */
  504.  
  505. #ifdef TERM_TABLE
  506.  
  507. TERM_TABLE_START(hp500c_driver)
  508.     "hp500c", "HP DeskJet 500c, [75 100 150 300] [rle tiff]",
  509.     HP500C_75PPI_XMAX, HP500C_75PPI_YMAX, HP500C_75PPI_VCHAR,
  510.     HP500C_75PPI_HCHAR, HP500C_75PPI_VTIC, HP500C_75PPI_HTIC, HP500Coptions,
  511.     HP500Cinit, HP500Creset, HP500Ctext, null_scale,
  512.     HP500Cgraphics, HP500Cmove, HP500Cvector, HP500Clinetype,
  513.     HP500Cput_text, HP500Ctext_angle, null_justify_text, do_point,
  514.     do_arrow, set_font_null, 0, TERM_BINARY
  515. TERM_TABLE_END(hp500c_driver)
  516.  
  517. #undef LAST_TERM
  518. #define LAST_TERM hp500c_driver
  519.  
  520. #endif /* TERM_TABLE */
  521. #endif /* TERM_PROTO_ONLY */
  522.  
  523. #ifdef TERM_HELP
  524. START_HELP(hp500c)
  525. "1 hp500c",
  526. "?commands set terminal hp500c",
  527. "?set terminal hp500c",
  528. "?set term hp500c",
  529. "?terminal hp500c",
  530. "?term hp500c",
  531. "?hp500c",
  532. " The `hp500c` terminal driver supports the Hewlett Packard HP DeskJet 500c.",
  533. " It has options for resolution and compression.",
  534. "",
  535. " Syntax:",
  536. "       set terminal hp500c {<res>} {<comp>}",
  537. "",
  538. " where `res` can be 75, 100, 150 or 300 dots per inch and `comp` can be \"rle\",",
  539. " or \"tiff\".  Any other inputs are replaced by the defaults, which are 75 dpi",
  540. " and no compression.  Rasterization at the higher resolutions may require a",
  541. " large amount of memory."
  542. END_HELP(hp500c)
  543. #endif /* TERM_HELP */
  544.